﻿var status = 0;
var choice;
var scrolls = Array(
Array("", 1040000, 0),
Array("", 1040002, 0),
Array("", 1040003, 0),
Array("", 1040004, 0),
Array("", 1040006, 0),
Array("", 1040007, 0),
Array("", 1040008, 0),
Array("", 1040009, 0),
Array("", 1040010, 0),
Array("", 1040011, 0),
Array("", 1040012, 0),
Array("", 1040013, 0),
Array("", 1040014, 0),
Array("", 1040015, 0),
Array("", 1040016, 0),
Array("", 1040017, 0),
Array("", 1040018, 0),
Array("", 1040019, 0),
Array("", 1040020, 0),
Array("", 1040021, 0),
Array("", 1040022, 0),
Array("", 1040023, 0),
Array("", 1040024, 0),
Array("", 1040025, 0),
Array("", 1040026, 0),
Array("", 1040028, 0),
Array("", 1040029, 0),
Array("", 1040030, 0),
Array("", 1040031, 0),
Array("", 1040032, 0),
Array("", 1040033, 0),
Array("", 1040034, 0),
Array("", 1040035, 0),
Array("", 1040036, 0),
Array("", 1040037, 0),
Array("", 1040038, 0),
Array("", 1040039, 0),
Array("", 1040040, 0),
Array("", 1040041, 0),
Array("", 1040042, 0),
Array("", 1040043, 0),
Array("", 1040044, 0),
Array("", 1040048, 0),
Array("", 1040049, 0),
Array("", 1040050, 0),
Array("", 1040057, 0),
Array("", 1040058, 0),
Array("", 1040059, 0),
Array("", 1040060, 0),
Array("", 1040061, 0),
Array("", 1040062, 0),
Array("", 1040063, 0),
Array("", 1040067, 0),
Array("", 1040068, 0),
Array("", 1040069, 0),
Array("", 1040070, 0),
Array("", 1040071, 0),
Array("", 1040072, 0),
Array("", 1040073, 0),
Array("", 1040074, 0),
Array("", 1040075, 0),
Array("", 1040076, 0),
Array("", 1040079, 0),
Array("", 1040080, 0),
Array("", 1040081, 0),
Array("", 1040082, 0),
Array("", 1040083, 0),
Array("", 1040084, 0),
Array("", 1040085, 0),
Array("", 1040086, 0),
Array("", 1040087, 0),
Array("", 1040088, 0),
Array("", 1040089, 0),
Array("", 1040090, 0),
Array("", 1040091, 0),
Array("", 1040092, 0),
Array("", 1040093, 0),
Array("", 1040094, 0),
Array("", 1040095, 0),
Array("", 1040096, 0),
Array("", 1040097, 0),
Array("", 1040098, 0),
Array("", 1040099, 0),
Array("", 1040100, 0),
Array("", 1040102, 0),
Array("", 1040103, 0),
Array("", 1040104, 0),
Array("", 1040105, 0),
Array("", 1040106, 0),
Array("", 1040107, 0),
Array("", 1040108, 0),
Array("", 1040109, 0),
Array("", 1040110, 0),
Array("", 1040111, 0),
Array("", 1040112, 0),
Array("", 1040113, 0),
Array("", 1040115, 0),
Array("", 1040116, 0),
Array("", 1040117, 0),
Array("", 1040118, 0),
Array("", 1040120, 0),
Array("", 1040121, 0),
Array("", 1040122, 0),
Array("", 1040145, 0),
Array("", 1040146, 0),
Array("", 1040147, 0),
Array("", 1040159, 0),
Array("", 1040160, 0),
Array("", 1040161, 0),
Array("", 1040162, 0),
Array("", 1040163, 0),
Array("", 1040164, 0),
Array("", 1040165, 0),
Array("", 1040166, 0),
Array("", 1040167, 0),
Array("", 1040168, 0),
Array("", 1040169, 0),
Array("", 1040170, 0),
Array("", 1040171, 0),
Array("", 1040172, 0),
Array("", 1040173, 0),
Array("", 1040174, 0),
Array("", 1040175, 0),
Array("", 1040176, 0),
Array("", 1040177, 0),
Array("", 1040178, 0),
Array("", 1040179, 0),
Array("", 1040180, 0),
Array("", 1040181, 0),
Array("", 1040182, 0),
Array("", 1040183, 0),
Array("", 1040184, 0),
Array("", 1040185, 0),
Array("", 1040187, 0),
Array("", 1040188, 0),
Array("", 1040189, 0),
Array("", 1041002, 0),
Array("", 1041003, 0),
Array("", 1041004, 0),
Array("", 1041006, 0),
Array("", 1041007, 0),
Array("", 1041008, 0),
Array("", 1041010, 0),
Array("", 1041011, 0),
Array("", 1041012, 0),
Array("", 1041013, 0),
Array("", 1041014, 0),
Array("", 1041015, 0),
Array("", 1041016, 0),
Array("", 1041017, 0),
Array("", 1041018, 0),
Array("", 1041019, 0),
Array("", 1041020, 0),
Array("", 1041021, 0),
Array("", 1041022, 0),
Array("", 1041023, 0),
Array("", 1041024, 0),
Array("", 1041025, 0),
Array("", 1041026, 0),
Array("", 1041027, 0),
Array("", 1041028, 0),
Array("", 1041029, 0),
Array("", 1041030, 0),
Array("", 1041031, 0),
Array("", 1041032, 0),
Array("", 1041033, 0),
Array("", 1041034, 0),
Array("", 1041035, 0),
Array("", 1041036, 0),
Array("", 1041037, 0),
Array("", 1041038, 0),
Array("", 1041039, 0),
Array("", 1041040, 0),
Array("", 1041041, 0),
Array("", 1041042, 0),
Array("", 1041043, 0),
Array("", 1041044, 0),
Array("", 1041045, 0),
Array("", 1041046, 0),
Array("", 1041047, 0),
Array("", 1041048, 0),
Array("", 1041049, 0),
Array("", 1041050, 0),
Array("", 1041051, 0),
Array("", 1041052, 0),
Array("", 1041053, 0),
Array("", 1041054, 0),
Array("", 1041055, 0),
Array("", 1041056, 0),
Array("", 1041057, 0),
Array("", 1041058, 0),
Array("", 1041059, 0),
Array("", 1041060, 0),
Array("", 1041061, 0),
Array("", 1041062, 0),
Array("", 1041063, 0),
Array("", 1041064, 0),
Array("", 1041065, 0),
Array("", 1041066, 0),
Array("", 1041067, 0),
Array("", 1041068, 0),
Array("", 1041069, 0),
Array("", 1041074, 0),
Array("", 1041075, 0),
Array("", 1041076, 0),
Array("", 1041077, 0),
Array("", 1041078, 0),
Array("", 1041079, 0),
Array("", 1041080, 0)
);

function start() {
    status = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) cm.dispose();
    else {
        if (status == 0 && mode == 0) {
            cm.dispose();
            return;
        } else if (status >= 1 && mode == 0) {
            cm.sendOk("好吧，欢迎下次继续光临！.");
            cm.dispose();
            return;
        }
        if (mode == 1) status++;
        else status--;

        if (status == 0) {
            choices = "\r\n兔兔币余额：#r" + cm.getHyPay(1) + "#k个 (#r买后不支持退货哟亲#k)";
            for (var i = 0; i < scrolls.length; i++) {
                choices += "\r\n#L" + i + "##v" + scrolls[i][1] + "##z" + scrolls[i][1] + "#　#d需要#r" + scrolls[i][2] + "#d兔兔币#k#l";
            }
            cm.sendSimpleS("欢迎来到上衣店,你想买我们商店的物品么?请选择吧：." + choices,2);
        } else if (status == 1) {
            cm.sendYesNo("你确定需要购买#v" + scrolls[selection][1] + "##t" + scrolls[selection][1] + "#?");
		choice = selection;
        } else if (status == 2) {
            var money = scrolls[choice][2];
            if (cm.getHyPay(1) < money) {
                cm.sendOk("抱歉，你没足够的兔兔币！");
                cm.dispose();
            } else {
                cm.addHyPay(money);
                cm.gainItem(scrolls[choice][1], 1);
                cm.sendOk("购买成功.");
                cm.dispose();
            }
        }
    }
}